package com.shpng.cheapenglish.persistent;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.shpng.cheapenglish.db.Word;

public class WordPersistent {

	private WordPersistent() {

	}

	private static WordPersistent wordPersistent;

	public static WordPersistent getInstance() {
		if (wordPersistent == null) {
			wordPersistent = new WordPersistent();
		}
		return wordPersistent;
	}

	@SuppressWarnings("unchecked")
	public List<Word> getWords(PersistenceManager pm) {
		Query query = pm.newQuery(Word.class);
		List<Word> words = (List<Word>) query.execute();

		return words;
	}

	public void saveWord(Word word, PersistenceManager pm) {
		pm.makePersistent(word);
		System.out.println("save word " + word.getWordString());
		return ;
	}

	public boolean deleteWord(Word word, PersistenceManager pm) {

		pm.deletePersistent(word);

		return true;
	}

}
